package cn.org.cute.ebocy.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5{

	private final static char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',  'E', 'F'};

    public static String getEncryptedText(String str){
       if(str == null)return null;
    	return getEncryptedText(str.getBytes());
    }

    public static String getEncryptedText(byte[] inbufBytes) {

    	String enc = null;

    	try{

    		MessageDigest md5 = MessageDigest.getInstance("MD5");

    		md5.update(inbufBytes);

    		byte tmp[] = md5.digest();

    		char str[] = new char[16 * 2];

    		int k = 0;
    		for (int i = 0; i < 16; i++) {

    			byte byte0 = tmp[i];
    			str[k++] = hexDigits[byte0 >>> 4 & 0xf];

    			str[k++] = hexDigits[byte0 & 0xf];
    		}

    		enc = new String(str).toLowerCase();
    	}
    	catch(NoSuchAlgorithmException e){
    		e.printStackTrace();
    	}

    	return enc;

    }

    public static void main(String[] s){
//    	for(int i=0;i<100;i++){
    		System.out.println(MD5.getEncryptedText("中华人民共和国test"));
//    	}
    }

}
